package com.innovation.wjrpc.convert;

import com.innovation.wjrpc.codec.Encoder;
import com.innovation.wjrpc.codec.impl.JSONEncoder;
import com.innovation.wjrpc.protocol.Request;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author innoyiya
 * @date 2021/9/8 11:15
 */
public class JavaToByte extends MessageToByteEncoder<Request> {

    private Encoder encoder = new JSONEncoder();

    @Override
    protected void encode(ChannelHandlerContext ctx, Request msg, ByteBuf out) throws Exception {
        out.writeBytes(encoder.encode(msg));
    }
}
